﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：AggregateRoot.cs
// 功能描述：TongTongMall
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using TongTongMall.Domain.Repositories.Attributes;
using TongTongMall.Domain.Repositories.Entities;
using TongTongMall.Events;

namespace TongTongMall.Domain.Entities
{
    public class AggregateRoot : AggregateRoot<long>, IAggregateRoot
    {

    }

    public class AggregateRoot<TPrimaryKey> : Entity<TPrimaryKey>, IAggregateRoot<TPrimaryKey>
    {

        protected TPrimaryKey _id;

        [Ignore]
        public TPrimaryKey AggregateRootId
        {
            get { return _id; }
            protected set { _id = value; }
        }

        [Ignore]
        public virtual Queue<IEventData> DomainEvents { get; }

        public AggregateRoot()
        {
            DomainEvents =  new Queue<IEventData>();
        }

        /// <summary>
        /// 预处理的领域事件
        /// </summary>
        /// <param name="eventData"></param>
        public void ApplyEvent(IEventData eventData)
        {
            if (eventData == null)
                throw new ArgumentException("eventData");
            DomainEvents.Enqueue(eventData);
        }
    }
}
